package com.leyou.page.listener;

import com.leyou.page.service.FileService;
import com.leyou.page.service.GoodsService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.validation.Valid;

/**
 * @author 岩冰
 * @version 1.0
 * @date:2018/10/16
 */
@Component
public class GoodsListener {
    @Autowired
    private FileService fileService;
    @RabbitListener(bindings = @QueueBinding(value =@Queue(value = "ly.create.index.queue",durable = "true"),
            exchange = @Exchange(value = "ly.item.exchange",ignoreDeclarationExceptions = "true",type = ExchangeTypes.TOPIC),
    key = {"item.insert","item.update"}))
    public void listenCreate(Long id) throws Exception {
        if (id == null) {
            return;
        }
        fileService.createHtml(id);
    }

    @RabbitListener(bindings = @QueueBinding(value = @Queue(value ="ly.delete.index.queue",durable = "true"),
    exchange = @Exchange(value = "ly.item.exchange",ignoreDeclarationExceptions = "true",type = ExchangeTypes.TOPIC),
            key ={"item.delete"} ))
    public void listenDelete(Long id) {
        if (id==null) {
            return;
        }
        this.fileService.deleteHtml(id);
    }
}
